home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / Bowers Development / AppMaker 2.0b5 / Examples / PowerPlant / NeoAccess / CMainWindow.cp < prev    next >
Encoding:
Text File  |  1995-10-08  |  4.1 KB  |  237 lines  |  [TEXT/MMCC]

  1. // CMainWindow.cp -- window methods
  2. // Created 10/5/95 8:02 PM by AppMaker
  3.  
  4. #include "CMainWindow.h"
  5.  
  6. #include <UReanimator.h>
  7. #include <URegistrar.h>
  8. #include <LStream.h>
  9. #include <LListBox.h>
  10. #include <LStdControl.h>
  11. #include "CAMReminderData.h"
  12. #include "CAdd.h"
  13. #include "CmdCodes.h"
  14.  
  15. #define PPob_MainWindowID    200
  16. #define RidL_MainWindowID    200
  17.  
  18. Boolean        CMainWindow::sIsRegistered = false;
  19.  
  20. //----------
  21. void
  22. CMainWindow::RegisterClass ()
  23. {
  24.     URegistrar::RegisterClass('Main', (ClassCreatorFunc)CMainWindow::CreateMainWindowStream);
  25.  
  26.     // register the pane classes we use
  27.  
  28.     sIsRegistered = true;
  29. }
  30.  
  31. //----------
  32. CMainWindow*
  33. CMainWindow::CreateMainWindow(
  34.     LCommander            *inSuperCommander,
  35.     CAMReminderData        *inData)
  36. {
  37.     if (!sIsRegistered) {
  38.         RegisterClass ();
  39.     }
  40.  
  41.     CMainWindow        *window;
  42.  
  43.     window = (CMainWindow *)LWindow::CreateWindow(PPob_MainWindowID, inSuperCommander);
  44.     window->ConnectToData (inData);
  45.  
  46.     return window;
  47. }
  48.  
  49. //----------
  50. //    This is the function you register with URegistrar to create a
  51. //    CMainWindow from a resource
  52.  
  53. CMainWindow*
  54. CMainWindow::CreateMainWindowStream(
  55.     LStream    *inStream)
  56. {
  57.     return (new CMainWindow(inStream));
  58. }
  59.  
  60. //----------
  61. CMainWindow::CMainWindow()
  62. {
  63. }
  64.  
  65. //----------
  66. CMainWindow::CMainWindow(
  67.     LStream    *inStream)
  68.         : LWindow(inStream)
  69. {
  70. }
  71.  
  72. //----------
  73. CMainWindow::~CMainWindow()
  74. {
  75. }
  76.  
  77. //----------
  78. //    This member function gets called once the containment hierarchy that contains
  79. //    this pane has been built. It gives us a chance to get data members for
  80. //    interesting subviews, and to do other operations now that our subviews exist.
  81. void
  82. CMainWindow::FinishCreateSelf()
  83. {
  84.     mRemindersList = (LListBox *)FindPaneByID('Remi');
  85.     mAddButton = (LStdButton *)FindPaneByID('Add ');
  86.     mEditButton = (LStdButton *)FindPaneByID('Edit');
  87.     mDeleteButton = (LStdButton *)FindPaneByID('Dele');
  88.  
  89.     UReanimator::LinkListenerToControls(this, this, RidL_MainWindowID);
  90.         // the purpose is to "connect" self to whatever controls
  91.         // that we want to "listen" to
  92.  
  93. // any additional initialization for your window:
  94.  
  95. }
  96.  
  97. //----------
  98. void
  99. CMainWindow::ConnectToData    (CAMReminderData        *inData)
  100. {
  101.     mData = inData;
  102.     inData->AddListener (this);
  103. }
  104.  
  105. //----------
  106. void
  107. CMainWindow::DoAddReminder ()
  108. {
  109. CAdd*    dialog = CAdd::CreateAdd(this);
  110. }
  111.  
  112. //----------
  113. void
  114. CMainWindow::DoEditReminder ()
  115. {
  116. CAdd*    dialog = CAdd::CreateAdd(this);
  117. }
  118.  
  119. //----------
  120. void
  121. CMainWindow::DoDeleteReminder ()
  122. {
  123. }
  124.  
  125. //----------
  126. void
  127. CMainWindow::ObeyAdd    (void*    ioParam)
  128. {
  129.     CAdd*    dialog = (CAdd *)ioParam;
  130.  
  131.     // do something with dialog's values
  132.  
  133.     delete dialog;
  134. }
  135.  
  136. //----------
  137. void
  138. CMainWindow::ListenToMessage(
  139.     MessageT    inMessage,
  140.     void        *ioParam)
  141. {
  142.     switch (inMessage) {
  143.  
  144.     case cmdAddReminder:
  145.         DoAddReminder ();
  146.         break;
  147.  
  148.     case cmdEditReminder:
  149.         DoEditReminder ();
  150.         break;
  151.  
  152.     case cmdDeleteReminder:
  153.         DoDeleteReminder ();
  154.         break;
  155.  
  156.     default:
  157.         break;
  158.     }
  159. }
  160.  
  161. //----------
  162. Boolean
  163. CMainWindow::ObeyCommand(
  164.     CommandT    inCommand,
  165.     void        *ioParam)
  166. {
  167.     Boolean        cmdHandled = true;
  168.  
  169.     switch (inCommand) {
  170.  
  171.     // +++ Add cases here for the commands you handle
  172.     //        Remember to add same cases to FindCommandStatus below
  173.     //        to enable/disable the commands
  174.  
  175.     case cmd_Add:
  176.         ObeyAdd    (ioParam);
  177.         break;
  178.  
  179.     default:
  180.             cmdHandled = LWindow::ObeyCommand(inCommand, ioParam);
  181.         break;
  182.     }
  183.  
  184.     return cmdHandled;
  185. }
  186.  
  187. //----------
  188. void
  189. CMainWindow::FindCommandStatus(
  190.     CommandT    inCommand,
  191.     Boolean        &outEnabled,
  192.     Boolean        &outUsesMark,
  193.     Char16        &outMark,
  194.     Str255        outName)
  195. {
  196.     outUsesMark = false;
  197.  
  198.     switch (inCommand) {
  199.  
  200.     // +++ Add cases here for the commands you handle
  201.     case cmdAddReminder:
  202.         outEnabled = true;
  203.         break;
  204.     case cmdEditReminder:
  205.         outEnabled = true;
  206.         break;
  207.     case cmdDeleteReminder:
  208.         outEnabled = true;
  209.         break;
  210.  
  211.     default:
  212.             LWindow::FindCommandStatus(inCommand, outEnabled,
  213.                                         outUsesMark, outMark, outName);
  214.         break;
  215.     }
  216. }
  217.  
  218. //----------
  219. Boolean
  220. CMainWindow::FocusDraw()
  221. {
  222.     Boolean        focused = LView::FocusDraw();
  223.  
  224.     if (focused) {
  225.         AuxWinHandle    awHndl;
  226.         CTabHandle        awCTable;
  227.         ColorSpec        contentSpec;
  228.  
  229.         GetAuxWin(GetMacPort(), &awHndl);
  230.         awCTable = (**awHndl).awCTable;
  231.         contentSpec = (**awCTable).ctTable [wContentColor];        // should search vs. index
  232.         ::RGBBackColor(&contentSpec.rgb);
  233.     }
  234.  
  235.     return focused;
  236. }
  237.